package base.thread;


public class Account {
	public static void main(String[] args) throws Exception{
		BankAccount account=new BankAccount(10000);
		int amount=1;
		int num=10000;
		Thread depo=new Thread(new Depositor(account,amount,num),"depo");
		Thread with=new Thread(new WithDrawer(account,amount,num),"with");
		
		depo.start();
		with.start();
		
		depo.join();
		with.join();
		
		System.out.println(account.getBalance());
	}
}

class Depositor implements Runnable {
	BankAccount account;
	int amount;
	int num;

	public Depositor(BankAccount account, int amount,int num) {
		this.account = account;
		this.amount = amount;
		this.num=num;
	}

	public void run() {
//		synchronized(account){
			for (int i = 0; i < num; i++) {
				account.depositor(amount);
			}
//		}
		
	}

}

class WithDrawer implements Runnable {

	BankAccount account;
	int amount;
	int num;

	public WithDrawer(BankAccount account, int amount,int num) {
		this.account = account;
		this.amount = amount;
		this.num=num;
	}

	public void run() {
//		synchronized(account){
			for (int i = 0; i < num; i++) {
				account.withDrawer(amount);
			}
//		}
	}

}

